<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>作品基本信息修改</title>
<link href="../style/css_member.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/common.js"></script>
<script src="../js/artDialog.js?skin=gray"></script>
<script src="../js/artDialog.iframeTools.js"></script>
<script type="text/javascript" src="../js/jquery-1.3.2.js"></script>
<script type="text/javascript" src="${ctx }/js/ajaxupload.js"></script>
<script language="javascript" type="text/javascript" src="${ctx }/js/My97DatePicker/WdatePicker.js"></script>

<script type="text/javascript">
//检查是否已选择作品用途
function checkUseOfPainting(){
	var checkflag = false;
	$($("input[name='painting.onSaleFlag']:checked")).each(function() {
		checkflag = true;
	});
	return checkflag;
}
//是否限量版
function chooseQqxl(flag){
	if(flag == '1'){
		$("#qqxlTr").show();
		$("#qqxl_radio_yes").attr("checked","checked");
	}else{
		$("#qqxlTr").hide();
		$("#qqxl_radio_no").attr("checked","checked");
	}
}

$(function(){
	$("#addPainterHref").click(function(){
		var p_id = $("#painter_id").val();
		art.dialog.open('${ctx}/painter/modifyPrepare.do?painter.id='+p_id,{title:'补充艺术家资料',width:820},false);
    });

	$("#paintingLink").click(function(){
		var s_Id = 2;
		if(checkChooseSharp()){
			s_Id = $("input[name='painting.sharpInfo.id']:checked").val();
		}else{
			alert("请先选择画框形状");
			return false;
		}
		art.dialog.open('${ctx}/fileUpload!uploadPrepare.do?imgType=painting&sharpId='+s_Id,{title:'上传作品图片',width:800,height:550},false);
    });

	new AjaxUpload("#upload_backimage_button2", {
		action : "${ctx }/painting/paintingAction!uploadImage.do",
		autoSubmit : true,
		name : "myFile",
		onSubmit : function(file, extension) {
			if (extension && /^(jpg|png|jpeg|gif)$/i.test(extension)) {
			} else {
				alert("你所选择的文件不受系统支持");
				return false;
			}
		},
		onComplete : function(file, response) {
			var jsonObj = eval('('+response+')');
			var code = jsonObj.code;
			var message = jsonObj.message;
			if( code == "0000"){
				$("#backimage_span2").text(message);
				$("#back_image2").val(message);
			}else{
				alert(message);
			}
		}
	});

	new AjaxUpload("#upload_backimage_button3", {
		action : "${ctx }/painting/paintingAction!uploadImage.do",
		autoSubmit : true,
		name : "myFile",
		onSubmit : function(file, extension) {
			if (extension && /^(jpg|png|jpeg|gif)$/i.test(extension)) {
			} else {
				alert("你所选择的文件不受系统支持");
				return false;
			}
		},
		onComplete : function(file, response) {
			var jsonObj = eval('('+response+')');
			var code = jsonObj.code;
			var message = jsonObj.message;
			if( code == "0000"){
				$("#backimage_span3").text(message);
				$("#back_image3").val(message);
			}else{
				alert(message);
			}
		}
	});

	new AjaxUpload("#upload_backimage_button4", {
		action : "${ctx }/painting/paintingAction!uploadImage.do",
		autoSubmit : true,
		name : "myFile",
		onSubmit : function(file, extension) {
			if (extension && /^(jpg|png|jpeg|gif)$/i.test(extension)) {
			} else {
				alert("你所选择的文件不受系统支持");
				return false;
			}
		},
		onComplete : function(file, response) {
			var jsonObj = eval('('+response+')');
			var code = jsonObj.code;
			var message = jsonObj.message;
			if( code == "0000"){
				$("#backimage_span4").text(message);
				$("#back_image4").val(message);
			}else{
				alert(message);
			}
		}
	});
});

//并初始化该作品的一二级分类、形状、是否限量、作品用途等选项
function init(){
	changeCatalogType();//初始化作品二级分类
	
	var painttypeid = '${painting.paintType.id}';
	$("#paintTypeSelect").val(painttypeid);
	choosePaintType('${painting.sharpInfo.id}');//初始化作品形状
	
	var qqxl = '${painting.qqxl }';//初始化是否限量
	if( qqxl != ''){
		chooseQqxl('1');
	}else{
		chooseQqxl('0');
	}

	var onSaleFlag = '${painting.onSaleFlag}';//初始化作品用途选项
	control_salestate(onSaleFlag);
}

function changeCatalogType(){
	var itemValue = $('#catalogTypeSelect').val();
	$.ajax( {
		type : "GET",
		url : "${ctx }/painting/findPaintTypeByCatalogId.do?catalogId="+ itemValue,
		timeout : 6000,
		async : false, //ajax同步
		success : function(data, textStatus) {
			$("#paintTypeSelect").empty();
			var items = eval(data);
			for ( var i = 0; i < items.length; i++) {
				$("#paintTypeSelect").append("<option value='"+items[i].id+"'>" + items[i].typeName+ "</option>");
			}
		}
	});
}

	/************  提交表单 ******************/
	function checkForm() {

		var title = $.trim($("#title").val());
		if (title == "") {
			$("#title").focus();
			alert("请填写商品名称。");
			return false;
		}
		
		var picImage = $("#picImage").val();
		if( picImage == "" ){
			alert("请上传作品图片。");
			return false;
		}

		var qqxl_radio = $("input[name='qqxl_radio']:checked").val();
		if(qqxl_radio == '0'){
			$("#qqxl").val("");
		}

		if (!checkUseOfPainting()) {
			alert("请选择作品用途。");
			return false;
		}

		var onSaleFlag = $("input[name='painting.onSaleFlag']:checked").val();
		if( onSaleFlag == "2" ){//上架销售
			var price = $.trim($("#price").val());
			if (!isNumber(price)) {
				$("#price").val("");
				$("#price").focus();
				alert("请正确填写价格，商品价格必须为数字。");
				return false;
			}
			var mktprice = $.trim($("#mktprice").val());
			if ( mktprice != "" && !isNumber(mktprice)) {
				$("#mktprice").val("");
				$("#mktprice").focus();
				alert("请正确填写优惠价格，优惠价格必须为数字。");
				return false;
			}
		}
		else if( onSaleFlag == "1" ){ //上拍处理
			var beginPrice = $("#beginPrice").val();
			if (!isNumber(beginPrice)) {
				$("#beginPrice").val("");
				$("#beginPrice").focus();
				alert("起拍价填写不正确。");
				return false;
			}
			var beginTime = $("#beginTime").val();
			if( beginTime == ""){
				alert("请填写拍卖起始时间。");
				return false;
			}
			var endTime = $("#endTime").val();
			if( endTime == ""){
				alert("请填写拍卖结束时间。");
				return false;
			}
			if(beginTime > endTime){
				alert("起拍时间和结束时间填写不合理，起拍时间必须小于结束时间。");
				return false;
			}
		}

		$("#publishPaintingForm").submit();
	}

	function control_salestate(saleFlag){
		if(saleFlag=='2'){//销售
			$("#priceTr").css("display","");
			$("#mktpriceTr").css("display","");
			$("#beginPriceTr").css("display","none");
			$("#beginTimeTr").css("display","none");
		}
		else if(saleFlag=='1'){//上拍
			$("#beginPriceTr").css("display","");
			$("#beginTimeTr").css("display","");
			$("#priceTr").css("display","none");
			$("#mktpriceTr").css("display","none");
		}
		else{//仅展示
			$("#priceTr").css("display","none");
			$("#mktpriceTr").css("display","none");
			$("#beginPriceTr").css("display","none");
			$("#beginTimeTr").css("display","none");
		}
	}

</script>
</head>

<body onload="init();"  style="background: #fff">

<form action="${ctx }/painting/modify_painting.do" method="post" id="publishPaintingForm" name="publishPaintingForm" enctype="multipart/form-data">
	<table width="800" border="0" cellpadding="0" cellspacing="0" style="background: #ffffff;">
      <tr>
        <td colspan="3" class="bt14A" align="center">修改作品资料</td>
      </tr>
      <tr>
        <td class="bt14A" align="right"><span class="style15">*</span>选择门类：</td>
        <td class="bt14A">
	        	<select name="painting.catalogType.id" id="catalogTypeSelect" onChange="changeCatalogType()">
	        		<c:forEach items="${catalogTypeList}" var="catalogType" varStatus="status">
					     <option value="${ catalogType.id}" <c:if test="${catalogType.id == painting.catalogType.id }">selected</c:if>/> ${ catalogType.name}</option>
				    </c:forEach>
	          </select></td>
	        	<td width="360" rowspan="13" valign="top">
		          <table width="360" height="384"  border="0" align="center" cellpadding="0" cellspacing="0">
		            <tr>
		              <td align="center">
		              <div id="photoTd" style="width: 200px;height: 300px;border: 1px solid #CCCCCC;">
		              	<img src="${painting.middleImageApath }" />
		              </div></td>
		            </tr>
		          </table>
	          </td>
      </tr>
      <tr>
        <td class="bt14A" align="right"><span class="style15">*</span>选择画种：</td>
        <td class="bt14A"><select name="painting.paintType.id" id="paintTypeSelect"></select></td>
      </tr>
      <tr>
        <td class="bt14A"><div align="right">商品名称：</div></td>
        <td class="bt14A"><input name="painting.title" type="text" size="20" id="title" value="${painting.title }"  maxlength="40"></td>
      </tr>
      <tr>
        <td class="bt14A" align="right"><span class="style20">*</span>画框形状：</td>
        <td class="bt14A">
	      	 <c:forEach items="${sharpInfoList}" var="sharpInfo"  varStatus="status">
				   <input onclick="choosePaintType('${sharpInfo.id }')" type="radio" name="painting.sharpInfo.id" value="${sharpInfo.id }" <c:if test="${ sharpInfo.id == painting.sharpInfo.id}">checked</c:if>/>${sharpInfo.name }
             </c:forEach>      
	     </td>
      </tr>
      <tr>
        <td class="bt14A" align="right"><span class="style20">*</span>上传作品：</td>
        <td class="bt14A"><span id="backimage_span"><a href="${painting.originalImagePath }" target="_blank">${painting.imageInfo.id }</a></span>
        	<span class="style18">
        	  	<a id="paintingLink" style="cursor: pointer;color: red">上传</a>
        	</span>
      </tr>
      <tr>
        <td class="bt14A" align="right">商品照片2：</td>
        <td class="bt14A"><span id="backimage_span2"><a href="${painting.originalImagePath2 }" target="_blank">${painting.imageInfo2.id }</a></span><a href="#" id="upload_backimage_button2" style="cursor: pointer;color: red">上传</a>
			<input type="hidden" name="back_image2" id="back_image2" value=""/></td>
      </tr>
      <tr>
        <td class="bt14A" align="right">商品照片3：</td>
        <td class="bt14A"><span id="backimage_span3"><a href="${painting.originalImagePath3 }" target="_blank">${painting.imageInfo3.id }</a></span><a href="#" id="upload_backimage_button3" style="cursor: pointer;color: red">上传</a>
			<input type="hidden" name="back_image3" id="back_image3" value=""/></td>
      </tr>
      <tr>
        <td class="bt14A" align="right">商品照片4：</td>
        <td class="bt14A"><span id="backimage_span4"><a href="${painting.originalImagePath4 }" target="_blank">${painting.imageInfo4.id }</a></span><a href="#" id="upload_backimage_button4" style="cursor: pointer;color: red">上传</a>
			<input type="hidden" name="back_image4" id="back_image4" value=""/></td>
      </tr>
      <tr>
        <td class="bt14A" align="right">艺术家姓名：</td>
        <td class="bt14A">
        	<input name="painter_name" type="text" size="10"  id="painter_name"  value="${painting.painter.name }">
            <input name="painting.painter.id" type="hidden" size="10"  id="painter_id" value="${painting.painter.id }">
            <span class="style18"><a id="addPainterHref" style="cursor: pointer;color: red">补充艺术家资料</a></span>
       </td>
      </tr>
     <c:if test="${requestScope.painterList != null && fn:length(requestScope.painterList)>0 }">
	      <tr><td></td>
		     <td style="padding-left: 5px;">
			     <select name="painterListSelect" id="painterListSelect" onchange="choosePainter()">
			     		<option value="">选择艺术家</option>
				        <c:forEach items="${requestScope.painterList}" var="painter" varStatus="status">
				       	 	<option value="${painter.id }">${painter.name }</option>
				       </c:forEach>
			     </select>
		     </td>
	      </tr>
      </c:if>
      <tr><td class="bt14A" align="right">上传证书</td><td class="bt14A"><input type="file" name="myFile" id="myFile"/></td></tr>
      <tr>
        <td class="bt14A" align="right">材 质：</td>
        <td class="bt14A"><input name="painting.caiZhi" type="text" size="10" id="caizhi" value="${painting.caiZhi }"></td>
        </tr>
      <tr>
        <td class="bt14A" align="right">尺 寸：</td>
        <td class="bt14A">
        	长<input name="painting.width" type="text" size="4" style="width: 60px;" id="width" value='<fmt:formatNumber value="${painting.width }" type="number" pattern="#.##"/>'>cm 
         	宽<input name="painting.hight" type="text" size="4" style="width: 60px;" id="height" value='<fmt:formatNumber value="${painting.hight }" type="number" pattern="#.##"/>'>cm
         	高<input name="painting.altitude" type="text" size="4" style="width: 60px;" id="altitude" value='<fmt:formatNumber value="${painting.altitude }" type="number" pattern="#.##"/>'>cm
         </td>
      </tr>
      <tr>
        <td class="bt14A" align="right">是否为限量版：</td>
        <td class="bt14A"><input type="radio" name="qqxl_radio" id="qqxl_radio_yes" onclick="chooseQqxl('1')" value="1"/>是<input type="radio" name="qqxl_radio" id="qqxl_radio_no"  onclick="chooseQqxl('0')" value="0"/>否</td>
      </tr>
      <tr id="qqxlTr" style="display: none">
        <td class="bt14A" align="right">全球限量：</td>
        <td class="bt14A">
	         <input name="painting.qqxl" type="text" size="10" id="qqxl" value="${painting.qqxl }">
	         <select name="painting.unit2">
        	 	  <option value="">请选择单位</option>
	              <option <c:if test="${painting.unit2 == '件' }">selected</c:if> value="件">件</option>
	              <option <c:if test="${painting.unit2 == '个' }">selected</c:if> value="个">个</option>
	              <option <c:if test="${painting.unit2 == '幅' }">selected</c:if> value="幅">幅</option>
	              <option <c:if test="${painting.unit2 == '瓶' }">selected</c:if> value="瓶">瓶</option>
	              <option <c:if test="${painting.unit2 == '支' }">selected</c:if> value="支">支</option>
	              <option <c:if test="${painting.unit2 == '座' }">selected</c:if> value="座">座</option>
	              <option <c:if test="${painting.unit2 == '盏' }">selected</c:if> value="盏">盏</option>
	              <option <c:if test="${painting.unit2 == '条' }">selected</c:if> value="条">条</option>
	              <option <c:if test="${painting.unit2 == '本' }">selected</c:if> value="本">本</option>
	              <option <c:if test="${painting.unit2 == '尊' }">selected</c:if> value="尊">尊</option>
	              <option <c:if test="${painting.unit2 == '对' }">selected</c:if> value="对">对</option>
	              <option <c:if test="${painting.unit2 == '套' }">selected</c:if> value="套">套</option>
	        </select>
        </td>
      </tr>
      <tr>
        <td class="bt14A" align="right">本次销售：</td>
        <td class="bt14A">
        	<input name="painting.store" type="text" size="10" id="store" value="${painting.store }">
        	<select name="painting.unit">
        	 	  <option value="">请选择单位</option>
	              <option <c:if test="${painting.unit == '件' }">selected</c:if> value="件">件</option>
	              <option <c:if test="${painting.unit == '个' }">selected</c:if> value="个">个</option>
	              <option <c:if test="${painting.unit == '幅' }">selected</c:if> value="幅">幅</option>
	              <option <c:if test="${painting.unit == '瓶' }">selected</c:if> value="瓶">瓶</option>
	              <option <c:if test="${painting.unit == '支' }">selected</c:if> value="支">支</option>
	              <option <c:if test="${painting.unit == '座' }">selected</c:if> value="座">座</option>
	              <option <c:if test="${painting.unit == '盏' }">selected</c:if> value="盏">盏</option>
	              <option <c:if test="${painting.unit == '条' }">selected</c:if> value="条">条</option>
	              <option <c:if test="${painting.unit == '本' }">selected</c:if> value="本">本</option>
	              <option <c:if test="${painting.unit == '尊' }">selected</c:if> value="尊">尊</option>
	              <option <c:if test="${painting.unit == '对' }">selected</c:if> value="对">对</option>
	              <option <c:if test="${painting.unit == '套' }">selected</c:if> value="套">套</option>
	        </select>
        </td>
      </tr>
      <tr>
        <td class="bt14A" align="right"><span class="style15">*</span>作品用途：</td>
        <td class="bt14A">
        	<input type="radio" name="painting.onSaleFlag" <c:if test="${painting.onSaleFlag == '0' }">checked</c:if> value="0" onclick="control_salestate('0')"/>仅展示
        	<input type="radio" name="painting.onSaleFlag" <c:if test="${painting.onSaleFlag == '2' }">checked</c:if> value="2" onclick="control_salestate('2')"/>销售
        	<input type="radio" name="painting.onSaleFlag" <c:if test="${painting.onSaleFlag == '1' }">checked</c:if> value="1" onclick="control_salestate('1')"/>上拍
        </td>
      </tr>
      <tr id="priceTr" style="display: none;">
        <td class="bt14A" align="right">标 价：</td>
        <td class="bt14A"><input name="painting.price" type="text" size="6" id="price" value='<fmt:formatNumber value="${painting.price }" type="number" pattern="#.##"/>'>元</td>
      </tr>
      <tr id="mktpriceTr" style="display: none;">
        <td class="bt14A" align="right">优惠价格：</td>
        <td class="bt14A"><input name="mktprice" type="text" size="6" id="mktprice" value='<fmt:formatNumber value="${requestScope.goods.mktprice }" type="number" pattern="#.##"/>'>元</td>
      </tr>
      <tr  id="beginPriceTr" style="display: none;">
      	  <td class="bt14A" align="right"><span class="style15">*</span>起拍价</td>
      	  <td class="bt14A"><input name="beginPrice" value='<fmt:formatNumber value="${bid.beginPrice }" type="number" pattern="#.##"/>' type="text" size="6" id="beginPrice">元</td>
      </tr>
      <tr id="beginTimeTr"  style="display: none;">
      	  <td class="bt14A" align="right"><span class="style15">*</span>拍卖起止时间</td>
      	  <td class="bt14A">
	      	  <input name="beginTime" value="<fmt:formatDate value='${bid.beginTime }' pattern='yyyy-MM-dd HH:mm'/>" type="text" size="13" style="width: 120px;" id="beginTime" onClick="WdatePicker({startDate:'%y-%M-%d 00:00:00',dateFmt:'yyyy-MM-dd HH:mm',alwaysUseStartDate:true})">
	      	  至<input name="endTime" value="<fmt:formatDate value='${bid.endTime }' pattern='yyyy-MM-dd HH:mm'/>" type="text" size="13"  style="width: 120px;" id="endTime" onClick="WdatePicker({startDate:'%y-%M-%d 00:00:00',dateFmt:'yyyy-MM-dd HH:mm',alwaysUseStartDate:true})">
      	  </td>
      </tr>
      <tr>
        <td class="bt14A" align="right">备注：</td>
        <td class="bt14A">
        	<select name="painting.remark">
        		<option value="">请选择</option>
        		<option value="1" <c:if test="${painting.remark == '1'}">selected="selected"</c:if>>真迹</option>
        		<option value="2" <c:if test="${painting.remark == '2'}">selected="selected"</c:if>>高仿</option>
        	</select>
        </td>
      </tr>
      <tr>
        <td width="120"></td>
        <td style="padding: 10px 0px 15px 5px;">
        	<input type="button" value="保存" onclick="checkForm()" style="cursor: pointer ;padding: 5px;" />
             <!-- 隐藏域  begin  -->
                <input name="painting.id" type="hidden"  id="painting_id" value="${painting.id }">
                <input name="painting.imageInfo.id" type="hidden"  id="picImage" value="${painting.imageInfo.id }">
             <!-- 隐藏域 end  -->
	     </td>
     </tr>
  </table>
</form>

</body>
</html>